//
//  MoreViewController.m
//  Movie
//
//  Created by tengyang on 15/7/17.
//  Copyright (c) 2015年 tengyang. All rights reserved.
//

#import "MoreViewController.h"
#import "UIImageView+WebCache.h"
#define kWidth self.view.bounds.size.width
#define kHeight self.view.bounds.size.height

@interface MoreViewController ()

@end

@implementation MoreViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title=@"更多";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createTableView];
    [self _createData];
    
    NSString *homePath=NSHomeDirectory();
    NSLog(@"%@",homePath);
   
}

- (void)viewWillAppear:(BOOL)animated
{
    [_tableView reloadData];
}

- (void)_createTableView
{
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 40, kWidth, kHeight)];
    _tableView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:_tableView];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    
    
    //去掉多余的分割线
    UIView *view1=[[UIView alloc]init];
    view1.backgroundColor=[UIColor clearColor];
    [_tableView setTableFooterView:view1];
    
}
- (void)_createData
{
    _dataArray =@[@"清除缓存",@"给个评价",@"检查新版本",@"商务合作",@"欢迎页",@"关于"];
    
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
    }
    if (indexPath.row==0) {
//        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(kWidth-40,0,40 , 20)];
        SDImageCache *cash=[SDImageCache sharedImageCache];
        CGFloat size=[cash getSize];

        cell.textLabel.text=[NSString stringWithFormat:@"%.1fM",size/1000/1000];
        cell.textLabel.textColor=[UIColor whiteColor];
    }
    else{
    cell.textLabel.text=_dataArray[indexPath.row];
    cell.textLabel.textColor=[UIColor whiteColor];
    }
    //UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    //image.image=[UIImage imageNamed:@"tab_bg_all"];
    cell.backgroundColor=[UIColor blackColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"清除所有缓存" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.delegate=self;
    [alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==1) {
        SDImageCache *cash=[SDImageCache sharedImageCache];
        [cash clearDisk];
        [_tableView reloadData];
    }
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
